<?php
class EmployeeManageAction extends Action {
	
	
	
	
	public function getUserActionDetail($customerUserId,$order="actionTime", $orderBy="desc", $start = 0, $limit = 25) {
		$CUserActionDetailModel = M("customer_user_action_detail");
	
		$retVal = Session::init();
		if (!$retVal) {
			Output::instance()->resultCode(code_access_denied);
			return;
		}
	
		$cid = Session::$user["customerId"];
		$condition['customerUserId']= array('eq',$customerUserId);
		
		$arr = $CUserActionDetailModel->where($condition)->order("$order $orderBy")->limit("$start, $limit")->select();
		
		if ($arr) {
			$count = $CUserActionDetailModel->where($condition)->count();
			Output::instance()->objArray($arr, $count);
		} else {
			Output::instance()->resultCode(code_success);
		}
		
		
		
	}
	
	
	/**
	 * session_init()在调用方法前使用
	 * @param unknown $cid
	 * @param unknown $customerUserId
	 * @param string $actionKeyword
	 * @param string $actionName
	 * @param string $content
	 * @param string $remark
	 */
	public function addUserActionDetail($cid,$customerUserId, $actionKeyword=NULL,$actionName=NULL,$content=NULL,$remark=NULL){
		Session::switchCustomer(0);
		$CUserActionDetailModel = M("customer_user_action_detail");
	
// 		$retVal = Session::init();
// 		if (!$retVal) {
// 			Output::instance()->resultCode(code_access_denied);
// 			return;
// 		}
	
// 		$cid = Session::$user["customerId"];
	
		
		if($customerUserId == null || $customerUserId == ''){
			Output::instance()->resultCode(code_sql_error);
			return;
		
		}
		$time = date("Y-m-d H:i:s");
		$data["customerUserId"] = $customerUserId;
		$data["actionKeyword"] = $actionKeyword;
		$data["actionName"] = $actionName;
		$data["content"] = $content;
		$data["remark"] = $remark;
		$data["actionTime"] = $time;
	
		$result = $CUserActionDetailModel->add($data);
		Session::switchCustomer($cid);
		if ($result) {
			$data["id"] = $result;
			Output::instance()->object($data);
		} else {
			Output::instance()->resultCode(code_sql_error);
		}
	}
	
	
	public function addUserAction($cid,$customerUserId, $actionKeyword=NULL,$actionName=NULL,$content=NULL,$remark=NULL){
		Session::switchCustomer(0);
		$CUserActionDetailModel = M("customer_user_action_detail");
	
// 		$retVal = Session::init();
// 		if (!$retVal) {
// 			Output::instance()->resultCode(code_access_denied);
// 			return;
// 		}
	
// 		$cid = Session::$user["customerId"];
	
		
		if($customerUserId == null || $customerUserId == ''){
			Output::instance()->resultCode(code_sql_error);
			return;
		
		}
		$time = date("Y-m-d H:i:s");
		$data["customerUserId"] = $customerUserId;
		$data["actionKeyword"] = $actionKeyword;
		$data["actionName"] = $actionName;
		$data["content"] = $content;
		$data["remark"] = $remark;
		$data["actionTime"] = $time;
	
		$result = $CUserActionDetailModel->add($data);
		Session::switchCustomer($cid);
		if ($result) {
			$data["id"] = $result;
			return $data;
		} else {
			return false;
		}
	}
	
	
}